package cn.itlaobing.ssm.web.filter;

import org.sitemesh.SiteMeshContext;
import org.sitemesh.builder.SiteMeshFilterBuilder;
import org.sitemesh.config.ConfigurableSiteMeshFilter;
import org.sitemesh.content.ContentProperty;
import org.sitemesh.content.tagrules.TagRuleBundle;
import org.sitemesh.content.tagrules.html.ExportTagToContentRule;
import org.sitemesh.tagprocessor.State;

/**
 * Created by xuaner on 2017/12/11.
 */
public class SiteMeshFilter extends ConfigurableSiteMeshFilter {
    @Override
    protected void applyCustomConfiguration(SiteMeshFilterBuilder builder) {
        super.applyCustomConfiguration(builder);
        builder.addDecoratorPath("/**","/WEB-INF/views/layout/application.jsp")
                .addExcludedPath("/assets/**")
        .addTagRuleBundle(new TagJsTag());
    }
    public class TagJsTag implements TagRuleBundle{

        @Override
        public void install(State defaultState, ContentProperty contentProperty, SiteMeshContext siteMeshContext) {
            defaultState.addRule("js", new ExportTagToContentRule(siteMeshContext, contentProperty.getChild("js"), false));
            defaultState.addRule("css", new ExportTagToContentRule(siteMeshContext, contentProperty.getChild("css"), false));
        }

        @Override
        public void cleanUp(State state, ContentProperty contentProperty, SiteMeshContext siteMeshContext) {

        }
    }
}
